﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace App.Store
{
    //预备区
    public partial class frmSamplePre : Form
    {

        Entities db = new Entities();

        T_Sample m_Sample = null;

        List<int> xID = new List<int>();


        public int m_samplexID
        {
            set
            {
                var samplelist = db.T_Sample.Where(a => a.xID == value);
                foreach (T_Sample sample in samplelist)
                {
                    m_Sample = sample;
                    break;
                }
                if (m_Sample == null) return;

                txtDCdivision.Text = m_Sample.custDept;
                if (m_Sample.bCanPrint == true) cBoxbCanPrint.Checked = true;
                txtDsKind.Text = m_Sample.sKind;
                txtDlocation.Text = m_Sample.location;
                txtDprintedCount.Text = m_Sample.printedCount.ToString();
                txtDoCount.Text = m_Sample.oCount.ToString();
                txtDsrCount.Text = m_Sample.srCount.ToString();
                txtDbCount.Text = m_Sample.bCount.ToString();
                txtDjCount.Text = m_Sample.jCount.ToString();
                txtDpCount.Text = m_Sample.pCount.ToString();
                txtDsCount.Text = m_Sample.sCount.ToString();
                txtDallCount.Text = m_Sample.allCount.ToString();
                txtDbarCode.Text = m_Sample.barCode;
                txtDproviderDept.Text = m_Sample.providerDept;
                txtDprodiver.Text = m_Sample.prodiver;
                txtDcontractNo.Text = m_Sample.contractNo;
                txtDsoleYard.Text = m_Sample.soleYard;
                txtDfactNo.Text = m_Sample.factNo;
                txtDpacking.Text = m_Sample.packing;
                txtDlMaterial.Text = m_Sample.lMaterial;
                txtDprice4.Text = m_Sample.price4.ToString();
                txtDyard4.Text = m_Sample.yard4;
                txtDprice3.Text = m_Sample.price3.ToString();
                txtDyard3.Text = m_Sample.yard3;
                txtDprice2.Text = m_Sample.price2.ToString();
                txtDyard2.Text = m_Sample.yard2;
                txtDprice1.Text = m_Sample.price1.ToString();
                txtDyard1.Text = m_Sample.yard1;
                txtDdesignNo.Text = m_Sample.designNo;
                txtDcolorCoding.Text = m_Sample.colorCode;
                txtDsType.Text = m_Sample.sType;
                txtDcustProductNo.Text = m_Sample.custProductNo;
                txtDxtNo.Text = m_Sample.xtNo;
                txtDsoleNo.Text = m_Sample.soleNo;
                txtDbmStruct.Text = m_Sample.bmStruct;
                txtDsoleMaterial.Text = m_Sample.soleMaterial;
                txtDbmMaterial.Text = m_Sample.bmMaterial;
                txtDseasonType.Text = m_Sample.seasonType;
                txtDseason.Text = m_Sample.season;
                txtDproperty.Text = m_Sample.property;
                txtDsize2.Text = m_Sample.size2;
                txtDsize1.Text = m_Sample.size1;
                txtDcolor.Text = m_Sample.color;
                txtDbrand.Text = m_Sample.brand;
                txtDfactory.Text = m_Sample.factory;
                txtDorderNo.Text = m_Sample.orderNo;
                txtDproductNo.Text = m_Sample.productNo;
                txtDsName.Text = m_Sample.sName;
            }
        }
        //public int m_bowplateProductNo
        //{
        //    set
        //    {
        //        var samplelist = db.T_Sample.Where(a => a.xID == value);
        //        foreach (T_Sample sample in samplelist)
        //        {
        //            m_Sample = sample;
        //            break;
        //        }
        //        if (m_Sample == null) return;

        //        txtDCdivision.Text = m_Sample.custDept;
        //        if (m_Sample.bCanPrint == true) cBoxbCanPrint.Checked = true;
        //        txtDsKind.Text = m_Sample.sKind;
        //        txtDlocation.Text = m_Sample.location;
        //        txtDprintedCount.Text = m_Sample.printedCount.ToString();
        //        txtDoCount.Text = m_Sample.oCount.ToString();
        //        txtDsrCount.Text = m_Sample.srCount.ToString();
        //        txtDbCount.Text = m_Sample.bCount.ToString();
        //        txtDjCount.Text = m_Sample.jCount.ToString();
        //        txtDpCount.Text = m_Sample.pCount.ToString();
        //        txtDsCount.Text = m_Sample.sCount.ToString();
        //        txtDallCount.Text = m_Sample.allCount.ToString();
        //        txtDbarCode.Text = m_Sample.barCode;
        //        txtDproviderDept.Text = m_Sample.providerDept;
        //        txtDprodiver.Text = m_Sample.prodiver;
        //        txtDcontractNo.Text = m_Sample.contractNo;
        //        txtDsoleYard.Text = m_Sample.soleYard;
        //        txtDfactNo.Text = m_Sample.factNo;
        //        txtDpacking.Text = m_Sample.packing;
        //        txtDlMaterial.Text = m_Sample.lMaterial;
        //        txtDprice4.Text = m_Sample.price4.ToString();
        //        txtDyard4.Text = m_Sample.yard4;
        //        txtDprice3.Text = m_Sample.price3.ToString();
        //        txtDyard3.Text = m_Sample.yard3;
        //        txtDprice2.Text = m_Sample.price2.ToString();
        //        txtDyard2.Text = m_Sample.yard2;
        //        txtDprice1.Text = m_Sample.price1.ToString();
        //        txtDyard1.Text = m_Sample.yard1;
        //        txtDdesignNo.Text = m_Sample.designNo;
        //        txtDcolorCoding.Text = m_Sample.colorCode;
        //        txtDsType.Text = m_Sample.sType;
        //        txtDcustProductNo.Text = m_Sample.custProductNo;
        //        txtDxtNo.Text = m_Sample.xtNo;
        //        txtDsoleNo.Text = m_Sample.soleNo;
        //        txtDbmStruct.Text = m_Sample.bmStruct;
        //        txtDsoleMaterial.Text = m_Sample.soleMaterial;
        //        txtDbmMaterial.Text = m_Sample.bmMaterial;
        //        txtDseasonType.Text = m_Sample.seasonType;
        //        txtDseason.Text = m_Sample.season;
        //        txtDproperty.Text = m_Sample.property;
        //        txtDsize2.Text = m_Sample.size2;
        //        txtDsize1.Text = m_Sample.size1;
        //        txtDcolor.Text = m_Sample.color;
        //        txtDbrand.Text = m_Sample.brand;
        //        txtDfactory.Text = m_Sample.factory;
        //        txtDorderNo.Text = m_Sample.orderNo;
        //        txtDproductNo.Text = m_Sample.productNo;
        //        txtDsName.Text = m_Sample.sName;
        //    }

        //}
        //public int m_originalshoeProductNo
        //{
        //    set
        //    {
        //        var samplelist = db.T_Sample.Where(a => a.xID == value);
        //        foreach (T_Sample sample in samplelist)
        //        {
        //            m_Sample = sample;
        //            break;
        //        }
        //        if (m_Sample == null) return;

        //        txtDCdivision.Text = m_Sample.custDept;
        //        if (m_Sample.bCanPrint == true) cBoxbCanPrint.Checked = true;
        //        txtDsKind.Text = m_Sample.sKind;
        //        txtDlocation.Text = m_Sample.location;
        //        txtDprintedCount.Text = m_Sample.printedCount.ToString();
        //        txtDoCount.Text = m_Sample.oCount.ToString();
        //        txtDsrCount.Text = m_Sample.srCount.ToString();
        //        txtDbCount.Text = m_Sample.bCount.ToString();
        //        txtDjCount.Text = m_Sample.jCount.ToString();
        //        txtDpCount.Text = m_Sample.pCount.ToString();
        //        txtDsCount.Text = m_Sample.sCount.ToString();
        //        txtDallCount.Text = m_Sample.allCount.ToString();
        //        txtDbarCode.Text = m_Sample.barCode;
        //        txtDproviderDept.Text = m_Sample.providerDept;
        //        txtDprodiver.Text = m_Sample.prodiver;
        //        txtDcontractNo.Text = m_Sample.contractNo;
        //        txtDsoleYard.Text = m_Sample.soleYard;
        //        txtDfactNo.Text = m_Sample.factNo;
        //        txtDpacking.Text = m_Sample.packing;
        //        txtDlMaterial.Text = m_Sample.lMaterial;
        //        txtDprice4.Text = m_Sample.price4.ToString();
        //        txtDyard4.Text = m_Sample.yard4;
        //        txtDprice3.Text = m_Sample.price3.ToString();
        //        txtDyard3.Text = m_Sample.yard3;
        //        txtDprice2.Text = m_Sample.price2.ToString();
        //        txtDyard2.Text = m_Sample.yard2;
        //        txtDprice1.Text = m_Sample.price1.ToString();
        //        txtDyard1.Text = m_Sample.yard1;
        //        txtDdesignNo.Text = m_Sample.designNo;
        //        txtDcolorCoding.Text = m_Sample.colorCode;
        //        txtDsType.Text = m_Sample.sType;
        //        txtDcustProductNo.Text = m_Sample.custProductNo;
        //        txtDxtNo.Text = m_Sample.xtNo;
        //        txtDsoleNo.Text = m_Sample.soleNo;
        //        txtDbmStruct.Text = m_Sample.bmStruct;
        //        txtDsoleMaterial.Text = m_Sample.soleMaterial;
        //        txtDbmMaterial.Text = m_Sample.bmMaterial;
        //        txtDseasonType.Text = m_Sample.seasonType;
        //        txtDseason.Text = m_Sample.season;
        //        txtDproperty.Text = m_Sample.property;
        //        txtDsize2.Text = m_Sample.size2;
        //        txtDsize1.Text = m_Sample.size1;
        //        txtDcolor.Text = m_Sample.color;
        //        txtDbrand.Text = m_Sample.brand;
        //        txtDfactory.Text = m_Sample.factory;
        //        txtDorderNo.Text = m_Sample.orderNo;
        //        txtDproductNo.Text = m_Sample.productNo;
        //        txtDsName.Text = m_Sample.sName;
        //    }
        //}
        //public int m_soleProductNo
        //{
        //    set
        //    {
        //        var samplelist = db.T_Sample.Where(a => a.xID == value);
        //        foreach (T_Sample sample in samplelist)
        //        {
        //            m_Sample = sample;
        //            break;
        //        }
        //        if (m_Sample == null) return;

        //        txtDCdivision.Text = m_Sample.custDept;
        //        if (m_Sample.bCanPrint == true) cBoxbCanPrint.Checked = true;
        //        txtDsKind.Text = m_Sample.sKind;
        //        txtDlocation.Text = m_Sample.location;
        //        txtDprintedCount.Text = m_Sample.printedCount.ToString();
        //        txtDoCount.Text = m_Sample.oCount.ToString();
        //        txtDsrCount.Text = m_Sample.srCount.ToString();
        //        txtDbCount.Text = m_Sample.bCount.ToString();
        //        txtDjCount.Text = m_Sample.jCount.ToString();
        //        txtDpCount.Text = m_Sample.pCount.ToString();
        //        txtDsCount.Text = m_Sample.sCount.ToString();
        //        txtDallCount.Text = m_Sample.allCount.ToString();
        //        txtDbarCode.Text = m_Sample.barCode;
        //        txtDproviderDept.Text = m_Sample.providerDept;
        //        txtDprodiver.Text = m_Sample.prodiver;
        //        txtDcontractNo.Text = m_Sample.contractNo;
        //        txtDsoleYard.Text = m_Sample.soleYard;
        //        txtDfactNo.Text = m_Sample.factNo;
        //        txtDpacking.Text = m_Sample.packing;
        //        txtDlMaterial.Text = m_Sample.lMaterial;
        //        txtDprice4.Text = m_Sample.price4.ToString();
        //        txtDyard4.Text = m_Sample.yard4;
        //        txtDprice3.Text = m_Sample.price3.ToString();
        //        txtDyard3.Text = m_Sample.yard3;
        //        txtDprice2.Text = m_Sample.price2.ToString();
        //        txtDyard2.Text = m_Sample.yard2;
        //        txtDprice1.Text = m_Sample.price1.ToString();
        //        txtDyard1.Text = m_Sample.yard1;
        //        txtDdesignNo.Text = m_Sample.designNo;
        //        txtDcolorCoding.Text = m_Sample.colorCode;
        //        txtDsType.Text = m_Sample.sType;
        //        txtDcustProductNo.Text = m_Sample.custProductNo;
        //        txtDxtNo.Text = m_Sample.xtNo;
        //        txtDsoleNo.Text = m_Sample.soleNo;
        //        txtDbmStruct.Text = m_Sample.bmStruct;
        //        txtDsoleMaterial.Text = m_Sample.soleMaterial;
        //        txtDbmMaterial.Text = m_Sample.bmMaterial;
        //        txtDseasonType.Text = m_Sample.seasonType;
        //        txtDseason.Text = m_Sample.season;
        //        txtDproperty.Text = m_Sample.property;
        //        txtDsize2.Text = m_Sample.size2;
        //        txtDsize1.Text = m_Sample.size1;
        //        txtDcolor.Text = m_Sample.color;
        //        txtDbrand.Text = m_Sample.brand;
        //        txtDfactory.Text = m_Sample.factory;
        //        txtDorderNo.Text = m_Sample.orderNo;
        //        txtDproductNo.Text = m_Sample.productNo;
        //        txtDsName.Text = m_Sample.sName;
        //    }
        //}

        private bool IsQuery = true;
        public frmSamplePre()
        {
            InitializeComponent();
            dataGridView();
        }

        private void frmSamplePre_Load(object sender, EventArgs e)
        {
            panlist.BringToFront();

            gvShoeSample.Visible = true;
            gvBowPlate.Visible = false;
            gvOriginalShoe.Visible = false;
            gvSole.Visible = false;

            rbShoeSample.Checked = true;
            Service.Brand(cbbrand);
            Service.Cust(cbcust);
            Service.Location(cblocation);
            Service.Factory(cbfactory);

            //this.gvShoeSample.SelectionMode = DataGridViewSelectionMode.FullRowSelect;//设置为整行被选中
            //this.gvBowPlate.SelectionMode = DataGridViewSelectionMode.FullRowSelect;//设置为整行被选中
            //this.gvOriginalShoe.SelectionMode = DataGridViewSelectionMode.FullRowSelect;//设置为整行被选中
            //this.gvSole.SelectionMode = DataGridViewSelectionMode.FullRowSelect;//设置为整行被选中

            if (Startup.GetApp().CurrentUser != null)
            {
                //tslb1.Text = "制单人：" + Startup.GetApp().CurrentUser.username;
                //tslb2.Text = "制单日期：" + DateTime.Now.ToLocalTime();
            }
        }

        private void gvID()
        {
            //if (gvShoeSample.RowCount > 0)
            //{
            //    int index = gvShoeSample.CurrentRow.Index;    //取得选中行的索引  
            //    this.m_samplexID = Convert.ToInt32(gvShoeSample.Rows[index].Cells["colxID"].Value.ToString());
            //}
            //else
            //{
            //    Msg.ShowWarning("请选择一行！");
            //}
            if (rbShoeSample.Checked)
            {
                if (gvShoeSample.RowCount > 0)
                {
                    int index = gvShoeSample.CurrentRow.Index;    //取得选中行的索引  
                    this.m_samplexID = Convert.ToInt32(gvShoeSample.Rows[index].Cells["colxID"].Value.ToString());
                }
                else
                {
                    Msg.ShowWarning("请选择一行！");
                }

            }
            else if (rbBowPlate.Checked)
            {
                if (gvBowPlate.RowCount > 0)
                {
                    int index = gvBowPlate.CurrentRow.Index;    //取得选中行的索引  
                    this.m_samplexID =Convert.ToInt32(gvBowPlate.Rows[index].Cells["colBxID"].Value.ToString());
                }
                else
                {
                    Msg.ShowWarning("请选择一行！");
                }
            }
            else if (rbOriginalShoe.Checked)
            {
                if (gvOriginalShoe.RowCount > 0)
                {
                    int index = gvOriginalShoe.CurrentRow.Index;    //取得选中行的索引  
                    this.m_samplexID =Convert.ToInt32(gvOriginalShoe.Rows[index].Cells["colOxID"].Value.ToString());
                }
                else
                {
                    Msg.ShowWarning("请选择一行！");
                }
            }
            else if (rbSole.Checked)
            {
                if (gvSole.RowCount > 0)
                {
                    int index = gvSole.CurrentRow.Index;    //取得选中行的索引  
                    this.m_samplexID = Convert.ToInt32(gvSole.Rows[index].Cells["colSxID"].Value.ToString());
                }
                else
                {
                    Msg.ShowWarning("请选择一行！");
                }
            }
        }

        private void rbGroup_CheckedChanged(object sender, EventArgs e)
        {
            if (rbShoeSample.Checked)
            {
                gvShoeSample.Visible = true;
                gvBowPlate.Visible = false;
                gvOriginalShoe.Visible = false;
                gvSole.Visible = false;
                gvShoeSample.DataSource = bs1;

                bnav.BindingSource = bs1;

            }
            else if (rbBowPlate.Checked)
            {
                gvShoeSample.Visible = false;
                gvBowPlate.Visible = true;
                gvOriginalShoe.Visible = false;
                gvSole.Visible = false;
                gvBowPlate.DataSource = bs2;

                bnav.BindingSource = bs2;

            }
            else if (rbOriginalShoe.Checked)
            {
                gvShoeSample.Visible = false;
                gvBowPlate.Visible = false;
                gvOriginalShoe.Visible = true;
                gvSole.Visible = false;
                gvOriginalShoe.DataSource = bs3;

                bnav.BindingSource = bs3;

            }
            else if (rbSole.Checked)
            {
                gvShoeSample.Visible = false;
                gvBowPlate.Visible = false;
                gvOriginalShoe.Visible = false;
                gvSole.Visible = true;
                gvSole.DataSource = bs4;

                bnav.BindingSource = bs4;

            }
        }

        private void dataGridView()
        {
            //样鞋绑定
            var gv1list = db.T_Sample.Where(a => a.pCount > 0 && a.sKind == "鞋样").ToList();
            bs1.DataSource = gv1list;

            //船头板绑定
            var gv2list = db.T_Sample.Where(a => a.pCount>0 && a.sKind == "船头板").ToList();
            bs2.DataSource = gv2list;

            //原版鞋绑定
            var gv3list = db.T_Sample.Where(a => a.pCount>0 && a.sKind == "原版鞋").ToList();
            bs3.DataSource = gv3list;

            //大底绑定
            var gv4list = db.T_Sample.Where(a => a.pCount>0 && a.sKind == "大底").ToList();
            bs4.DataSource = gv4list;
        }

        private void btndetail_Click(object sender, EventArgs e)
        {
            gvID();
            if (this.IsQuery)
            {
                this.pandetail.BringToFront();
                this.btndetail.Text = "概要";
                this.IsQuery = false;
                //if (rbShoesSample.Checked)
                //{
                //    cTabs1.SelectTab(tabShoeSample);
                //}
                //else if (rbBowPlate.Checked)
                //{
                //    cTabs1.SelectTab(tabBowPlate);
                //}
                //else if (rbOriginalShoe.Checked)
                //{
                //    cTabs1.SelectTab(tabOriginShoe);
                //}
                //else if (rbSole.Checked)
                //{
                //    cTabs1.SelectTab(tabSole);
                //}
            }
            else
            {
                this.panlist.BringToFront();
                this.btndetail.Text = "明细";
                this.IsQuery = true;

            }
        }

        ListViewItem lvi=null;

        private void gvShoeSample_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 0 && e.RowIndex != -1)
            {

                lvi = new ListViewItem();

                if (bool.Parse(this.gvShoeSample.Rows[e.RowIndex].Cells[0].EditedFormattedValue.ToString()) == true)
                {
                    this.lvlist.BeginUpdate();

                    //int index = gvShoeSample.CurrentRow.Index;    //取得选中行的索引  


                    lvi.Text = gvShoeSample.Rows[e.RowIndex].Cells["colProductNo"].Value.ToString();

                    xID.Add(Convert.ToInt32(gvShoeSample.Rows[e.RowIndex].Cells["colxID"].Value.ToString()));

                    //foreach(ListViewItem lv in lvlist.SelectedItems)
                    //{
                    //    if (lvi.Text != lv.Text)
                    //    { }     
                    //}
                    this.lvlist.Items.Add(lvi);
                    this.lvlist.EndUpdate();

                }
                else if (bool.Parse(this.gvShoeSample.Rows[e.RowIndex].Cells[0].EditedFormattedValue.ToString()) == false)
                {
                    this.lvlist.BeginUpdate();

                    lvi.Text = gvShoeSample.Rows[e.RowIndex].Cells["colProductNo"].Value.ToString();

                    xID.Remove(Convert.ToInt32(gvShoeSample.Rows[e.RowIndex].Cells["colxID"].Value.ToString()));

                    foreach (ListViewItem lv in lvlist.Items)
                    {
                        if (lv.Text == lvi.Text)
                            lvlist.Items.Remove(lv);
                    }

                    this.lvlist.EndUpdate();
                }
            }
        }

        private void btnPreOperation_Click(object sender, EventArgs e)
        {
            frmSamplePreOpetation frmSPO = new frmSamplePreOpetation();
            frmSPO.xID = this.xID;

            if (frmSPO.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                //this.dataGridView();//更新预备区数据
                this.lvlist.Items.Clear();
            }
        }

        private void btnState_Click(object sender, EventArgs e)
        {
            frmStateSelect frmSS = new frmStateSelect();
            if (rbShoeSample.Checked)
            {
                int index = gvShoeSample.CurrentRow.Index;    //取得选中行的索引  
                frmSS.m_xID = Convert.ToInt32(gvShoeSample.Rows[index].Cells["colxID"].Value.ToString());
            }
            else if (rbBowPlate.Checked)
            {
                int index = gvBowPlate.CurrentRow.Index;    //取得选中行的索引  
                frmSS.m_xID = Convert.ToInt32(gvBowPlate.Rows[index].Cells["colBxID"].Value.ToString());
            }
            else if (rbOriginalShoe.Checked)
            {
                int index = gvOriginalShoe.CurrentRow.Index;    //取得选中行的索引  
                frmSS.m_xID = Convert.ToInt32(gvOriginalShoe.Rows[index].Cells["colOxID"].Value.ToString());
            }
            else if(rbSole.Checked)
            {
                int index = gvSole.CurrentRow.Index;    //取得选中行的索引  
                frmSS.m_xID = Convert.ToInt32(gvSole.Rows[index].Cells["colOxID"].Value.ToString());
            }
            frmSS.ShowDialog();
        }

        private void gvBowPlate_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 0 && e.RowIndex != -1)
            {

                lvi = new ListViewItem();

                if (bool.Parse(this.gvBowPlate.Rows[e.RowIndex].Cells[0].EditedFormattedValue.ToString()) == true)
                {
                    this.lvlist.BeginUpdate();

                    //int index = gvShoeSample.CurrentRow.Index;    //取得选中行的索引  

                    lvi.Text = gvBowPlate.Rows[e.RowIndex].Cells["colBowProductNo"].Value.ToString();

                    xID.Add(Convert.ToInt32(gvBowPlate.Rows[e.RowIndex].Cells["colBxID"].Value.ToString()));
                    //foreach(ListViewItem lv in lvlist.SelectedItems)
                    //{
                    //    if (lvi.Text != lv.Text)
                    //    { }     
                    //}
                    this.lvlist.Items.Add(lvi);
                    this.lvlist.EndUpdate();

                }
                else if (bool.Parse(this.gvBowPlate.Rows[e.RowIndex].Cells[0].EditedFormattedValue.ToString()) == false)
                {
                    this.lvlist.BeginUpdate();

                    lvi.Text = gvBowPlate.Rows[e.RowIndex].Cells["colBowProductNo"].Value.ToString();
                    xID.Remove(Convert.ToInt32(gvBowPlate.Rows[e.RowIndex].Cells["colBxID"].Value.ToString()));
                    foreach (ListViewItem lv in lvlist.Items)
                    {
                        if (lv.Text == lvi.Text)
                            lvlist.Items.Remove(lv);
                    }

                    this.lvlist.EndUpdate();
                }
            }
        }

        private void gvOriginalShoe_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 0 && e.RowIndex != -1)
            {

                lvi = new ListViewItem();

                if (bool.Parse(this.gvOriginalShoe.Rows[e.RowIndex].Cells[0].EditedFormattedValue.ToString()) == true)
                {
                    this.lvlist.BeginUpdate();

                    //int index = gvShoeSample.CurrentRow.Index;    //取得选中行的索引  


                    lvi.Text = gvOriginalShoe.Rows[e.RowIndex].Cells["colOProductNo"].Value.ToString();
                    xID.Add(Convert.ToInt32(gvOriginalShoe.Rows[e.RowIndex].Cells["colOxID"].Value.ToString()));
                    //foreach(ListViewItem lv in lvlist.SelectedItems)
                    //{
                    //    if (lvi.Text != lv.Text)
                    //    { }     
                    //}
                    this.lvlist.Items.Add(lvi);
                    this.lvlist.EndUpdate();

                }
                else if (bool.Parse(this.gvOriginalShoe.Rows[e.RowIndex].Cells[0].EditedFormattedValue.ToString()) == false)
                {
                    this.lvlist.BeginUpdate();

                    lvi.Text = gvOriginalShoe.Rows[e.RowIndex].Cells["colOProductNo"].Value.ToString();

                    xID.Remove(Convert.ToInt32(gvOriginalShoe.Rows[e.RowIndex].Cells["colOxID"].Value.ToString()));

                    foreach (ListViewItem lv in lvlist.Items)
                    {
                        if (lv.Text == lvi.Text)
                            lvlist.Items.Remove(lv);
                    }

                    this.lvlist.EndUpdate();
                }
            }
        }

        private void gvSole_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 0 && e.RowIndex != -1)
            {

                lvi = new ListViewItem();

                if (bool.Parse(this.gvSole.Rows[e.RowIndex].Cells[0].EditedFormattedValue.ToString()) == true)
                {
                    this.lvlist.BeginUpdate();

                    //int index = gvShoeSample.CurrentRow.Index;    //取得选中行的索引  

                    lvi.Text = gvSole.Rows[e.RowIndex].Cells["colSProductNo"].Value.ToString();
                    xID.Add(Convert.ToInt32(gvSole.Rows[e.RowIndex].Cells["colSxID"].Value.ToString()));
                    //foreach(ListViewItem lv in lvlist.SelectedItems)
                    //{
                    //    if (lvi.Text != lv.Text)
                    //    { }     
                    //}
                    this.lvlist.Items.Add(lvi);
                    this.lvlist.EndUpdate();

                }
                else if (bool.Parse(this.gvSole.Rows[e.RowIndex].Cells[0].EditedFormattedValue.ToString()) == false)
                {
                    this.lvlist.BeginUpdate();

                    lvi.Text = gvSole.Rows[e.RowIndex].Cells["colSProductNo"].Value.ToString();

                    xID.Remove(Convert.ToInt32(gvSole.Rows[e.RowIndex].Cells["colSxID"].Value.ToString()));

                    foreach (ListViewItem lv in lvlist.Items)
                    {
                        if (lv.Text == lvi.Text)
                            lvlist.Items.Remove(lv);
                    }

                    this.lvlist.EndUpdate();
                }
            }
        }

        private void btnAllChoose_Click(object sender, EventArgs e)
        {
            if (gvShoeSample.RowCount > 0)
            {
                for (int i = 0; i < gvShoeSample.RowCount; i++)
                {
                    if (bool.Parse(this.gvShoeSample.Rows[i].Cells[0].EditedFormattedValue.ToString()) == true)
                    {
                        continue;
                    }
                    else
                    {
                        this.gvShoeSample.Rows[i].Cells[0].Value = true;
                        this.lvlist.BeginUpdate();
                        lvi = new ListViewItem();

                        lvi.Text = gvShoeSample.Rows[i].Cells[2].Value.ToString();

                        xID.Add(Convert.ToInt32(gvShoeSample.Rows[i].Cells["colxID"].Value.ToString()));

                        
                        if (!lvlist.Items.Contains(lvi))
                        {
                            lvlist.Items.Add(lvi);
                        }
                        this.lvlist.EndUpdate();
                    }                  
                }
            }
        }

        private void btnNoChoose_Click(object sender, EventArgs e)
        {
            if (gvShoeSample.RowCount > 0)
            {
                lvlist.Items.Clear();
                for (int i = 0; i < gvShoeSample.RowCount; i++)
                {
                    if (bool.Parse(this.gvShoeSample.Rows[i].Cells[0].EditedFormattedValue.ToString()) == true)
                    {
                        this.gvShoeSample.Rows[i].Cells[0].Value = false;
                        this.lvlist.BeginUpdate();
                        lvi = new ListViewItem();
                        lvi.Text = gvShoeSample.Rows[i].Cells[2].Value.ToString();

                        xID.Remove(Convert.ToInt32(gvShoeSample.Rows[i].Cells["colxID"].Value.ToString()));

                        lvlist.Items.Remove(lvi);

                        this.lvlist.EndUpdate();
                    }
                    else
                    {
                        this.gvShoeSample.Rows[i].Cells[0].Value = true;
                        this.lvlist.BeginUpdate();
                        lvi = new ListViewItem();

                        lvi.Text = gvShoeSample.Rows[i].Cells[2].Value.ToString();

                        xID.Add(Convert.ToInt32(gvShoeSample.Rows[i].Cells["colxID"].Value.ToString()));
                        
                        if (!lvlist.Items.Contains(lvi))
                        {
                            lvlist.Items.Add(lvi);
                        }
                        this.lvlist.EndUpdate();
                    }
                }
            }
        }

        private void btnmemuCancel_Click(object sender, EventArgs e)
        {
            if (gvShoeSample.RowCount > 0)
            {
                for (int i = 0; i < gvShoeSample.RowCount; i++)
                {
                    if (bool.Parse(this.gvShoeSample.Rows[i].Cells[0].EditedFormattedValue.ToString()) == false)
                    {
                        continue;
                    }
                    else
                    {
                        this.gvShoeSample.Rows[i].Cells[0].Value = false;

                        xID.Remove(Convert.ToInt32(gvShoeSample.Rows[i].Cells["colxID"].Value.ToString()));

                        lvlist.Items.Clear();
                    }
                }
            }
        }


        private void btnzld_Click(object sender, EventArgs e)
        {
            //ExcelBase excel = new ExcelBase();
            ////creates the main header
            //ExcelBE be = null;
            //be = new ExcelBE(5, 2, "Total of Products", "B5", "D5", "YELLOW", true, 10, "n", null);
            //excel.InsertData(be);
            ////creates subheaders
            //be = new ExcelBE(6, 2, "Sold Product", "B6", "B6", "GRAY", true, 10, "", null);
            //excel.InsertData(be);
            //be = new ExcelBE(6, 3, "", "C6", "C6", "GRAY", true, 10, "", null);
            //excel.InsertData(be);
            //be = new ExcelBE(6, 4, "Initial Total", "D6", "D6", "GRAY", true, 10, "", null);
            //excel.InsertData(be);
            ////add Data to cells
            //be = new ExcelBE(7, 2, "114287", "B7", "B7", null, false, 10, "", "#,##0");
            //excel.InsertData(be);
            //be = new ExcelBE(7, 3, "", "C7", "C7", null, false, 10, "", null);
            //excel.InsertData(be);
            //be = new ExcelBE(7, 4, "129121", "D7", "D7", null, false, 10, "", "#,##0");
            //excel.InsertData(be);
            ////add percentage row
            //be = new ExcelBE(8, 2, "", "B8", "B8", null, false, 10, "", "");
            //excel.InsertData(be);
            //be = new ExcelBE(8, 3, "=B7/D7", "C8", "C8", null, false, 10, "", "0.0%");
            //excel.InsertData(be);
            //be = new ExcelBE(8, 4, "", "D8", "D8", null, false, 10, "", "");
            //excel.InsertData(be);
            ////add empty divider
            //be = new ExcelBE(9, 2, "", "B9", "D9", "GAINSBORO", true, 10, "", null);
            //excel.InsertData(be); 

        }

    }
}
